//
//  CircleView.m
//  CAShapeLayer实现圆形进度条效果
//
//  Created by 超群 on 15/6/13.
//  Copyright (c) 2015年 haotoufa.Team. All rights reserved.
//

#import "CircleView.h"

@interface CircleView ()

@property (strong, nonatomic) CAShapeLayer* shapeLayer;

@end

@implementation CircleView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //创建出CAShapeLayer
        _shapeLayer         = [CAShapeLayer layer];
        _shapeLayer.frame   = self.bounds;
        
        _shapeLayer.shadowRadius    = 0.3;
        _shapeLayer.shadowColor     = [UIColor blackColor].CGColor;
       //创建贝塞尔曲线
        UIBezierPath* path  = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
        //建立联系
        _shapeLayer.path    = path.CGPath;
        
        _shapeLayer.fillColor   = [UIColor clearColor].CGColor;
        _shapeLayer.lineWidth   = 1.0f;
        _shapeLayer.strokeColor = [UIColor redColor].CGColor;
        _shapeLayer.strokeEnd   = 0.f;
        
        [self.layer addSublayer:_shapeLayer];

    }
    return self;
}

@synthesize startValue = _startValue;
-(void)setStartValue:(CGFloat)startValue
{
    _startValue             = startValue;
    _shapeLayer.strokeEnd   = startValue;
}
-(CGFloat)startValue
{
    return _startValue;
}

@synthesize lineWith = _lineWith;
-(void)setLineWith:(CGFloat)lineWith
{
    _lineWith                   = lineWith;
    if (lineWith<0) {
        _shapeLayer.lineWidth   = 0;
    }
    _shapeLayer.lineWidth       = lineWith;
}
-(CGFloat)lineWith
{
    return _lineWith;
}

@synthesize lineColor = _lineColor;
-(void)setLineColor:(UIColor *)lineColor
{
    _lineColor              = lineColor;
    _shapeLayer.strokeColor = lineColor.CGColor;
}
-(UIColor *)lineColor
{
    return _lineColor;
}

@synthesize value = _value;
-(void)setValue:(CGFloat)value
{
    _value = value;
    if (value<0) {
        _shapeLayer.strokeEnd = 0;
    }else if (value >1){
        _shapeLayer.strokeEnd = 1;
    }
    _shapeLayer.strokeEnd     = value;
        
}
-(CGFloat)value
{
    return _value;
}









@end
